{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# python中的list的去重方法"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 一、用set"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{1, 2, 3, 5, 7, 9, 10}\n"
     ]
    }
   ],
   "source": [
    "# 直接使用Set,但会打乱之前的顺序\n",
    "lis = [5, 2, 2, 1, 3, 7, 7, 9, 9, 10, 10]\n",
    "lis = set(lis)\n",
    "print(lis)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 二、用字典的fromkeys"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "dict_keys([5, 2, 1, 3, 7, 9, 10])\n",
      "[5, 2, 1, 3, 7, 9, 10]\n"
     ]
    }
   ],
   "source": [
    "lis = [5, 2, 2, 1, 3, 7, 7, 9, 9, 10, 10]\n",
    "lis = {}.fromkeys(lis)\n",
    "print(lis.keys())\n",
    "print(list(lis.keys()))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
